require('./app.styl');

// if (__LOCAL__ && window.chrome && window.chrome.webstore) { // This is a Chrome only hack
//     // see https://github.com/livereload/livereload-extensions/issues/26
//     setInterval(function() {
//         document.body.focus();
//     }, 200);
// }
// bind fastclick
window.FastClick && FastClick.attach(document.body);
//路由器就是React的一个组件
const { Router, Route, IndexRoute, Link, hashHistory } = ReactRouter;
const PageHome = require('../pages/home');
const PageCheck = require('../pages/check');
const PageIntegration= require('../pages/integration');
const PageTest= require('../pages/test');
const DB = require('./db');
const DingClient = require('../config/DingClient');
class App extends React.Component {
    getNetData(){
        alert('jsapi验证开始');
        //获取json数据，then成功，catch异常
        // params动态参数
        DB.dingClientAPI.getConfigInfo()
        .then(function(jsonData) {
             let configdata = jsonData;
             alert('数据='+configdata); 
             DingClient.clientConfig(configdata.content,function(isSuccessed,data){
                 if(isSuccessed){
                     alert('jsapi验证成功');
                      dd.biz.navigation.setTitle({
                         title : 'jsapi',
                          onSuccess : function(result) {
                           },
                          onFail : function(err) {}
                       });
                 }else{
                 alert(data.error);
               }
             });            
        })
        .catch(function(error) {
            //  alert(error);
        });
    }
    render() {
         this.getNetData();
        return (
            <div>
                {this.props.children}
            </div>
        );
    }
}

ReactDOM.render(
//真正的路由要通过Route组件定义,hashHistory-路由的切换由URL的hash变化决定，即URL的#部分发生变化
//Route组件定义了URL路径与组件的对应关系,history监听浏览器地址栏的变化
    <Router history={hashHistory}>
        <Route name="app" path="/" component={App}>
            <IndexRoute component={PageHome}/>
            <Route path="home"  component={PageHome}/>
            <Route path="check" component={PageCheck}/>
            <Route path="integration" component={PageIntegration}/>
            <Route path="test" component={PageTest}/>
        </Route>
    </Router>,
    document.getElementById('App')
);
